package cn.itcast.mapper;

import cn.itcast.domain.Orders;
import cn.itcast.domain.User;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface UserMapper {

    //查询所有用户及其订单编号和商品信息
    @Select("select * from user")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "sex",property = "sex"),
            @Result(property = "ordersList",javaType = List.class,column = "id",
                    many = @Many(select = "cn.itcast.mapper.OrdersMapper.findByUid",fetchType = FetchType.LAZY))
    })

    List<User> findAll();

    @Select("select * from user where id = #{oid}")
    User findByOid(int oid);
}
